package com.jar.exercise.反射.reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectionTest {
	public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
		Class<Student> studentClass = Student.class;
		Class<?> aClass = Class.forName("com.jar.exercise.反射.reflection.Student");
		Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(String.class, Integer.class);
		declaredConstructor.setAccessible(true);

		Student stu = (Student) declaredConstructor.newInstance("张珊", 12);
		System.out.println(stu.getAge() + stu.getName());
		Constructor<?> declaredConstructor1 = aClass.getDeclaredConstructor();
		Student student = (Student) declaredConstructor1.newInstance();
		System.out.println(student.getName());
	}
}
